const _ = require("lodash");

const models = require(__base + '/models');
const errcode = require(__util + "/errcode");
const ct = require(__util + "/catch"); // 路由错误捕获(不使用则不会捕获异常错误)

module.exports = ct(async (req, res) => {
  const { field } = req.body

  if (!field) {
    return res.json(errcode.APP_DISTINCT_FIELD_INVALID)
  }

  const ret = await models.ThirdPartyApp.aggregate(field, 'DISTINCT', {
    plain: false
  })
  .map(row => row.DISTINCT)
  
  res.json(
    errcode.SUCCESS(ret)
  )
})